Entity Framework Core: Get a List of All the Tables
Entity Framework Core: Get a List of All the Tables
37105-Sep-2023
Updated on 06-Sep-2023
Home / DeveloperSection / Forums / Entity Framework Core: Get a List of All the Tables
Entity Framework Core: Get a List of All the Tables
Aryan Kumar
06-Sep-2023You can get a list of all the tables in your Entity Framework Core database using the
Model
property of your DbContext class. TheModel
property is the collection of all the entities that are associated with the database.The following code gets a list of all the tables in the database:
C#
This code returns a collection of
EntityType
objects. EachEntityType
object represents a table in the database.Then you can traverse through the collection of
EntityType
object to get the names of the tables. For example, the following code prints the names of all the tables in the database:C#
Here are the few other things to keep in mind when getting a list of all the tables in an Entity Framework Core database:
Where
operator to filter the query results.OrderBy
operator sort the query results.Take
andSkip
operators to paginate the query results.